package com.baor.vip.service.impl;

import com.baor.common.core.domain.R;
import com.baor.vip.domain.CarVO;
import com.baor.vip.mapper.CarMapper;
import com.baor.vip.service.CarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class CarServiceImpl implements CarService {
    @Autowired
    private CarMapper carMapper;

    @Override
    public R carAdd(CarVO carVO) {
//        System.out.println("uid"+carVO.getCommoId());
        //有没有判断
        if(carMapper.selectCommo(carVO.getCommoId()) != 0){
            //增加数量
            return R.ok(carMapper.addNum(carVO));
        }
        return R.ok(carMapper.carAdd(carVO));
    }

    @Override
    public R carList(Integer vipUid) {
        return R.ok(carMapper.carList(vipUid));
    }

    @Override
    public R goodsNum(Map<String,Integer> map) {
        System.out.println("num:"+map.get("num"));
        if(map.get("num") <= 0){
            return R.fail("数量不对");
        }
        return R.ok(carMapper.updateNum(map));
    }

    @Override
    public R delCar(Integer[] carId) {
        return R.ok(carMapper.delCars(carId));
    }

}
